package com.rzjm.exercise.common.utils;

import java.util.Random;

/**
 * @Author felix
 * @Date 2019/5/8 9:45
 */
public class GenerateSelfId {

    public static String getId(int number) {
        StringBuilder str=new StringBuilder();//定义变长字符串
        Random random=new Random();
        //随机生成数字，并添加到字符串
        for(int i = 0; i < number; i++){
            str.append(random.nextInt(10));
        }
        return str.toString();
    }

    public static String getId(int number, String ... oldId) {
        StringBuilder str=new StringBuilder();//定义变长字符串
        Random random=new Random();
        //随机生成数字，并添加到字符串
        for(int i = 0; i < number; i++){
            str.append(random.nextInt(10));
        }
        if (ArrayUtils.containsIgnoreCase(oldId, str.toString())) {
            return getId(number, oldId);
        }
        return str.toString();
    }
}
